package tmall.action;


import org.apache.struts2.convention.annotation.Action;

import tmall.pojo.Category;
import tmall.pojo.Property;
import tmall.pojo.PropertyValue;
import tmall.util.Page;

public class PropertyAction extends Action4Result{

	@Action("admin_property_list")
	public String list(){
		if(page == null)
			page = new Page();
		int total = propertyService.total(category);
		page.setTotal(total);
		page.setParam("&category.id="+category.getId());
		properties = propertyService.list(page, category);
		
		category = (Category) categoryService.get(category.getId());
		return "listProperty";
	}
	
	@Action("admin_property_add")
	public String add(){
		propertyService.save(property);
		return "listPropertyPage";
	}
	
	@Action("admin_property_delete")
	public String delete(){
		property = (Property) propertyService.get(property.getId());		
		propertyService.delete(property);
		return "listPropertyPage";
	}
	
	@Action("admin_property_edit")
	public String edit(){
		int id = property.getId();
		property = (Property) propertyService.get(id);
		return "editProperty";
	}
	
	@Action("admin_property_update")
	public String update(){
		propertyService.update(property);
		return "listPropertyPage";
	}
	
}
